#!/bin/bash

# 自动检测系统类型并执行SSL升级脚本（支持FNOS/DSM/通用Linux）

# 检测群辉DSM（优先级最高）
if [ -f /etc/synoinfo.conf ] && [ -d /var/packages ]; then
    echo "[INFO] 检测到群辉DSM系统，执行专用脚本..."
    bash -c "$(curl -fsSL https://gitee.com/banban1000/docker/raw/master/dsm/dsmupcert.sh)"
    exit $?
fi

# 精准检测FNOS系统（Debian基础 + vol1磁盘格式）
if grep -q "ID=debian" /etc/os-release && ls /vol1* &>/dev/null; then
    echo "[INFO] 检测到FNOS系统（Debian+vol1磁盘），执行..."
    bash -c "$(curl -fsSL https://gitee.com/banban1000/docker/raw/master/fnos/fnosupcert.sh)"
    exit $?
fi

# 检测其他Debian系统（非FNOS情况）
if grep -q "ID=debian" /etc/os-release; then
    echo "[WARNING] 检测到Debian系统但未检测到vol1磁盘"
    echo "[诊断] 磁盘结构: $(ls /vol* 2>/dev/null || echo "无vol前缀磁盘")"
    bash -c "$(curl -fsSL https://gitee.com/banban1000/docker/raw/master/linux/linuxupcert.sh)"
    exit $?
fi

# 其他Linux系统
if [ -f /etc/os-release ]; then
    echo "[INFO] 检测到通用Linux系统: $(grep PRETTY_NAME /etc/os-release | cut -d '"' -f 2)"
    bash -c "$(curl -fsSL https://gitee.com/banban1000/docker/raw/master/linux/linuxupcert.sh)"
    exit $?
fi

# 未知系统
echo "[ERROR] 系统识别失败！调试信息："
echo "----------------------------------------"
echo "1. 系统标识: $(cat /etc/os-release 2>/dev/null || echo "无/etc/os-release")"
echo "2. 内核信息: $(uname -a)"
echo "----------------------------------------"
exit 1